<?php
/**
 * Created by PhpStorm.
 * User: C。
 * Date: 2019/8/13
 * Time: 9:04
 */
namespace app\home\controller;

use app\common\model\Flike as FlikeModel;

/**
 * 点赞控制器
 * Class Fgroup
 * @package app\home\controller
 */
class Flike extends Base
{
    /**
     * [getAdd  点赞]
     * @param
     * @return json
     * @author [C。]
     */
    public function postAdd()
    {
        $param = input('param.');
        $model = new FlikeModel();
        $mem = $this->getMember($param['token']);
        $res = $model->getAllData(['fgroup_id'=>$param['fgroup_id'],'memid'=>$mem['id']]);
        if(!empty($res)){
            return admin_json(2, '已经点赞过了!');
        }
        try{
            $data = array(
                'memid'=>$mem['id'],
                'fgroup_id'=>$param['fgroup_id'],
                'addtime'=>time()
            );
            $model->addData($data);
        }catch(\Exception $e){
            systembug($e->getMessage(),2,$this->url);
            return admin_json(-1, '点赞失败'.$e->getMessage());
        }
        return admin_json(1, '点赞成功');
    }
}